﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Enter.Utils.CryptoExt
{
	/*
 使用此工具生成的时候一定要选择，PKCS1

下载地址：https://doc.open.alipay.com/docs/doc.htm?treeId=291&articleId=105971&docType=1

此外还可以使用OpenSSL工具命令来生成：https://doc.open.alipay.com/docs/doc.htm?articleId=106130&docType=1
 */
	public static class RSAExtend
    {

		//2048 公钥
		static string publicKey = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4ePR2LBNYh+H6VXlhAKchMSZvRzZI1nWrlm7QrFSs2/fv8EcB8EkI0NThKdKX2l17rvK6P0A4kDrZC59DLmHyg80QNfimETdcEJrTjyvhJ8pbnckZ0T53v22JRsNFbFk1C/g29jx6zG0+afDnBr8DvVWHzg9xN144148RzgbQS/HUD0qGJWRhHSPpjL6mxxDsusYxVxuDBDFcankTo0HsXAnuNoPiQVlgtfDXzW3KfIbtUuqbk+hegxmo8jCiXcsSTAHN5PvIlj2LEy6Sh3ieCVBMusHDAgIeDP9sfDeWFIqEw/ENjOho5MxK7oQVYeqPWmCmL/pMt7WDYsGCtX1WQIDAQAB";
		//2048 私钥
		static string privateKey = @"MIIEpAIBAAKCAQEA4ePR2LBNYh+H6VXlhAKchMSZvRzZI1nWrlm7QrFSs2/fv8EcB8EkI0NThKdKX2l17rvK6P0A4kDrZC59DLmHyg80QNfimETdcEJrTjyvhJ8pbnckZ0T53v22JRsNFbFk1C/g29jx6zG0+afDnBr8DvVWHzg9xN144148RzgbQS/HUD0qGJWRhHSPpjL6mxxDsusYxVxuDBDFcankTo0HsXAnuNoPiQVlgtfDXzW3KfIbtUuqbk+hegxmo8jCiXcsSTAHN5PvIlj2LEy6Sh3ieCVBMusHDAgIeDP9sfDeWFIqEw/ENjOho5MxK7oQVYeqPWmCmL/pMt7WDYsGCtX1WQIDAQABAoIBAQDBh0G9+C4UJxd2HZVpqCMYzKc6koCl/M4kydPZq7pC6VI1Iuk065B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7h4mLvMUH8TFbio1658X50ecJBiLk2CsnllXNHJ+N/9naSxg0BCErw/rdlWtvuLrGfMh9+TMPle/MD9lA==";

		static RSAHelper CryptoRSA = new RSAHelper(RSAType.RSA2, Encoding.UTF8, privateKey, publicKey);

		/// <summary>
		/// 加密
		/// </summary>
		public static string Encrypt(string value)
		{
			return CryptoRSA.Encrypt(value);
		}
		/// <summary>
		/// 解密
		/// </summary>
		public static string Decrypt(string value)
		{
			return CryptoRSA.Decrypt(value);
		}
		
	}
}
